﻿using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using SBlogCore.Common.FluentValidatorExtend;
using Microsoft.Extensions.DependencyInjection;
using SBlogCore.Common.DatabaseAccessor;

namespace SBlogCore.Common.MiddlewareExtend
{
    /// <summary>
    /// 自定义中间件Demo
    /// </summary>
    [SkipScan]
    public class MigrateDataBaseMiddleware
    {
        private readonly RequestDelegate _next;

        public MigrateDataBaseMiddleware(RequestDelegate next)
        {
            _next = next;
        }

        public async Task InvokeAsync(HttpContext context, IServiceProvider serviceProvider)
        {
            //var dbContext = serviceProvider.GetService<GlobalDbContext>();
            //if (dbContext != null && dbContext.Database.IsSqlServer())
            //    await dbContext.Database.MigrateAsync();
            await _next(context);
        }
    }
}
